{extend name='base' /}

{block name='main'}
<div class="main-panel">
    <div class="content">
        <div class="page-inner">
            <div class="row">
                <div class="col-md-12">
                    <div class="card">
                        <div class="card-header">
                            <h4 class="card-title">编辑学生</h4>
                        </div>
                        <div class="card-body">
                            <form id="form">
                                <div class="form-group form-inline">
                                    <label for="school_id" class="col-md-2 col-form-label">所属学校 <span style="color: #f00;">*</span></label>
                                    <div class="col-md-10 p-0">
                                        <select name="data[school_id]" id="school_id" class="form-control">
                                            <option value="">请选择学校</option>
                                            {foreach $school as $key=>$vo }
                                            <option value="{$vo.id}" {if $vo.id==$score.school_id}selected{/if}>{$vo.name}</option>
                                            {/foreach}
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group form-inline">
                                    <label for="class_id" class="col-md-2 col-form-label">所属年级 <span style="color: #f00;">*</span></label>
                                    <div class="col-md-10 p-0">
                                        <select name="data[class_id]" id="class_id" class="form-control">
                                            <option value="">请选择年级</option>
                                            {foreach $class as $key=>$vo }
                                            <option value="{$vo.id}" {if $vo.id==$score.class_id}selected{/if}>{$vo.name}</option>
                                            {/foreach}
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group form-inline">
                                    <label for="stu_id" class="col-md-2 col-form-label">所属学生 <span style="color: #f00;">*</span></label>
                                    <div class="col-md-10 p-0">
                                        <select name="data[stu_id]" id="stu_id" class="form-control">
                                            <option value="">请选择学生</option>
                                            {foreach $student as $key=>$vo }
                                            <option value="{$vo.id}" {if $vo.id==$score.stu_id}selected{/if}>{$vo.name}</option>
                                            {/foreach}
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group form-inline">
                                    <label for="course_id" class="col-md-2 col-form-label">所属课程 <span style="color: #f00;">*</span></label>
                                    <div class="col-md-10 p-0">
                                        <select name="data[course_id]" id="course_id" class="form-control">
                                            <option value="">请选择课程</option>
                                            {foreach $course as $key=>$vo }
                                            <option value="{$vo.id}" {if $vo.id==$score.course_id}selected{/if}>{$vo.name}</option>
                                            {/foreach}
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group form-inline">
                                    <label for="course_id" class="col-md-2 col-form-label">成绩类型 <span style="color: #f00;">*</span></label>
                                    <div class="col-md-10 p-0">
                                        <select name="data[score_id]" id="score_id" class="form-control">
                                            <option value="">请选择成绩类型</option>
                                            {foreach $scoretype as $key=>$vo }
                                            <option value="{$vo.id}" {if $vo.id==$score.score_id}selected{/if}>{$vo.name}</option>
                                            {/foreach}
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group form-inline">
                                    <label for="title" class="col-md-2 col-form-label">成绩名称 <span style="color: #f00;">*</span></label>
                                    <div class="col-md-10 p-0">
                                        <input type="text" class="form-control" id="title" name="data[name]" placeholder="请输入成绩名称" value="{$score.name}">
                                    </div>
                                </div>
                                <div class="form-group form-inline">
                                    <label for="title" class="col-md-2 col-form-label">总分数 <span style="color: #f00;">*</span></label>
                                    <div class="col-md-10 p-0">
                                        <input type="text" class="form-control" id="total" name="data[total]" placeholder="请输入总分数" value="{$score.total}">
                                    </div>
                                </div>
                                <div class="form-group form-inline">
                                    <label for="title" class="col-md-2 col-form-label">成绩 <span style="color: #f00;">*</span></label>
                                    <div class="col-md-10 p-0">
                                        <input type="text" class="form-control" id="score" name="data[score]" placeholder="请输入成绩" value="{$score.score}">
                                    </div>
                                </div>
                                <div class="form-group form-inline">
                                    <label for="title" class="col-md-2 col-form-label">考试时间 <span style="color: #f00;">*</span></label>
                                    <div class="col-md-10 p-0">
                                        <input type="date" class="form-control" id="time" name="data[time]" placeholder="请输入考试时间" value="{$score.time}">
                                    </div>
                                </div>
                                <div class="form-group form-inline">
                                    <label class="col-md-2 col-form-label"></label>
                                    <div class="col-md-10 p-0">
                                        <button type="button" class="btn btn-success" onclick="add();">立即提交</button>
                                        <button type="button" class="btn btn-danger" onclick="window.history.back()">返回</button>
                                    </div>
                                </div>
                                <input type="hidden" name="id" value="{$score.id}">
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}

{block name='js'}
<script>
    var lock = false;
    function add() {
        if (lock) {
            return false;
        }
        lock = true;
        $.ajax({
            url: "{:url('score/edit')}",
            type: 'post',
            data: $("#form").serialize(),
            dataType: 'json',
            success: function (res) {
                if (res.code == 0) {
                    swal("提示", res.msg, {
                        icon : "error",
                        buttons: {
                            confirm: {
                                className : 'btn btn-danger'
                            }
                        },
                    });
                    lock = false;
                }else{
                    window.history.back();
                }
            }
        })
    }
</script>
{/block}